#include "mytest_api.h"

_tstring getLocTime()
{
#if 0
    time_t timep; time(&timep);
    struct tm* p = localtime(&timep);

    char ctm[64];
    std::sprintf(ctm, "%d%d%d%d%d%d"
                 , (1900+p->tm_year), (1+p->tm_mon), p->tm_mday
                 , (p->tm_hour + 12) , p->tm_min , p->tm_sec);
    return _tstring(ctm);
#endif

    struct timespec tp;
    struct tm nowTime;

    clock_gettime(CLOCK_REALTIME, &tp);
    localtime_r(&tp.tv_sec, &nowTime);

    char current[1024];
    sprintf(current, "%04d-%02d-%02d %02d:%02d:%02d"
            , nowTime.tm_year + 1900
            , nowTime.tm_mon+1
            , nowTime.tm_mday
            , nowTime.tm_hour
            , nowTime.tm_min
            , nowTime.tm_sec
            );

    return _tstring(current);
}

int is_dir_exist(_tcstring & dir)
{
    if (dir.empty()) return -1;
    if (opendir(dir.c_str()) == NULL) return -1;
    return 0;
}

void GetVector(std::vector<StAppInfo> &vct)
{
    StAppInfo st1;
        st1.strReadme = "This is a ivi application for austin";
        st1.strName = "IVI_HMI";
        st1.strVersion = "0.1";
        vct.push_back(st1);

    StAppInfo st2;
        st2.strReadme = "This is a alexa-hmi demo application for homescreen";
        st2.strName = "alexa-hmi";
        st2.strVersion = "1.0";
        vct.push_back(st2);

    StAppInfo st3;
        st3.strReadme = "This is a sdl-hmi demo application for homescreen";
        st3.strName = "sdl-hmi";
        st3.strVersion = "1.0";
        vct.push_back(st3);

    StAppInfo st4;
        st4.strReadme = "This is a demo application for sdl_navi_player";
        st4.strName = "sdl_navi_player";
        st4.strVersion = "0.1";
        vct.push_back(st4);

    StAppInfo st5;
        st5.strReadme = "This is a demo dashboard application";
        st5.strName = "Dashboard";
        st5.strVersion = "0.1";
        vct.push_back(st5);

    StAppInfo st6;
        st6.strReadme = "NAVIGATION App";
        st6.strName = "Navigation";
        st6.strVersion = "0.1";
        vct.push_back(st6);

    StAppInfo st7;
        st7.strReadme = "AGL Default Mixer";
        st7.strName = "mixer";
        st7.strVersion = "6.90.0-04990a8";
        vct.push_back(st7);

    StAppInfo st8;
        st8.strReadme = "POI App";
        st8.strName = "POI";
        st8.strVersion = "0.1";
        vct.push_back(st8);
}
